﻿using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace Studio
{
	// Token: 0x020004A9 RID: 1193
	public class SceneInfo
	{
		// Token: 0x06001DCF RID: 7631 RVA: 0x000BCA7C File Offset: 0x000BAC7C
		public SceneInfo(GameScreenShotAssist _assistt)
		{
			this.dicObject = new Dictionary<int, ObjectInfo>();
			this.cameraData = new CameraControl.CameraData[10];
			for (int i = 0; i < this.cameraData.Length; i++)
			{
				this.cameraData[i] = new CameraControl.CameraData();
			}
			this.hashIndex = new HashSet<int>();
			this.gameScreenShotAssist = _assistt;
			ChangeAmount changeAmount = this.caMap;
			changeAmount.onChangePos = (Action)Delegate.Combine(changeAmount.onChangePos, new Action(Singleton<MapCtrl>.Instance.Reflect));
			ChangeAmount changeAmount2 = this.caMap;
			changeAmount2.onChangeRot = (Action)Delegate.Combine(changeAmount2.onChangeRot, new Action(Singleton<MapCtrl>.Instance.Reflect));
			this.Init();
		}

		// Token: 0x17000331 RID: 817
		// (get) Token: 0x06001DD0 RID: 7632 RVA: 0x000BCB94 File Offset: 0x000BAD94
		public Version version
		{
			get
			{
				return this.m_Version;
			}
		}

		// Token: 0x17000332 RID: 818
		// (get) Token: 0x06001DD1 RID: 7633 RVA: 0x000BCB9C File Offset: 0x000BAD9C
		// (set) Token: 0x06001DD2 RID: 7634 RVA: 0x000BCBA4 File Offset: 0x000BADA4
		public Dictionary<int, ObjectInfo> dicImport { get; private set; }

		// Token: 0x17000333 RID: 819
		// (get) Token: 0x06001DD3 RID: 7635 RVA: 0x000BCBB0 File Offset: 0x000BADB0
		// (set) Token: 0x06001DD4 RID: 7636 RVA: 0x000BCBB8 File Offset: 0x000BADB8
		public Dictionary<int, int> dicChangeKey { get; private set; }

		// Token: 0x06001DD5 RID: 7637 RVA: 0x000BCBC4 File Offset: 0x000BADC4
		public void Init()
		{
			this.dicObject.Clear();
			this.map = -1;
			this.caMap.Reset();
			this.atmosphere = 0;
			this.enableSSAO = true;
			this.ssaoIntensity = 1f;
			this.ssaoRadius = 1f;
			this.ssaoColor = Utility.ConvertColor(23, 11, 11);
			this.enableBloom = true;
			this.bloomIntensity = 1f;
			this.bloomDirt = false;
			this.enableDepth = false;
			this.depthFocalSize = 1f;
			this.depthAperture = 0.7f;
			this.enableVignette = true;
			this.vignetteVignetting = 1f;
			this.enableEyeAdaptation = false;
			this.eyeAdaptationIntensity = 0.5f;
			this.enableNoise = false;
			this.noiseIntensity = 1f;
			this.cameraSaveData = null;
			this.cameraData = new CameraControl.CameraData[10];
			if (Singleton<Studio>.IsInstance())
			{
				for (int i = 0; i < 10; i++)
				{
					this.cameraData[i] = Singleton<Studio>.Instance.cameraCtrl.ExportResetData();
				}
			}
			this.cameraLightColor = Utility.ConvertColor(220, 210, 204);
			this.cameraLightIntensity = 1f;
			this.cameraLightRot[0] = 0f;
			this.cameraLightRot[1] = 0f;
			this.cameraLightShadow = true;
			this.cameraMethod = 0;
			this.bgmCtrl.play = false;
			this.bgmCtrl.repeat = BGMCtrl.Repeat.All;
			this.bgmCtrl.no = 0;
			this.envCtrl.play = false;
			this.envCtrl.repeat = BGMCtrl.Repeat.All;
			this.envCtrl.no = 0;
			this.outsideSoundCtrl.play = false;
			this.outsideSoundCtrl.repeat = BGMCtrl.Repeat.All;
			this.outsideSoundCtrl.fileName = string.Empty;
			this.background = string.Empty;
			this.skybox = -1;
			this.hashIndex.Clear();
		}

		// Token: 0x06001DD6 RID: 7638 RVA: 0x000BCDB4 File Offset: 0x000BAFB4
		public int GetNewIndex()
		{
			int num = 0;
			while (MathfEx.RangeEqualOn<int>(0, num, 2147483647))
			{
				if (!this.hashIndex.Contains(num))
				{
					this.hashIndex.Add(num);
					return num;
				}
				num++;
			}
			return -1;
		}

		// Token: 0x06001DD7 RID: 7639 RVA: 0x000BCE00 File Offset: 0x000BB000
		public int CheckNewIndex()
		{
			int num = -1;
			while (MathfEx.RangeEqualOn<int>(0, num, 2147483647))
			{
				if (!this.hashIndex.Contains(num))
				{
					return num;
				}
				num++;
			}
			return -1;
		}

		// Token: 0x06001DD8 RID: 7640 RVA: 0x000BCE40 File Offset: 0x000BB040
		public bool SetNewIndex(int _index)
		{
			return this.hashIndex.Add(_index);
		}

		// Token: 0x06001DD9 RID: 7641 RVA: 0x000BCE50 File Offset: 0x000BB050
		public void DeleteIndex(int _index)
		{
			this.hashIndex.Remove(_index);
		}

		// Token: 0x06001DDA RID: 7642 RVA: 0x000BCE60 File Offset: 0x000BB060
		public bool Save(string _path)
		{
			using (FileStream fileStream = new FileStream(_path, FileMode.Create, FileAccess.Write))
			{
				using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
				{
					byte[] buffer = this.CreatePngScreen(320, 180);
					binaryWriter.Write(buffer);
					binaryWriter.Write(this.m_Version.ToString());
					this.Save(binaryWriter, this.dicObject);
					binaryWriter.Write(this.map);
					this.caMap.Save(binaryWriter);
					binaryWriter.Write(this.atmosphere);
					binaryWriter.Write(this.enableSSAO);
					binaryWriter.Write(this.ssaoIntensity);
					binaryWriter.Write(this.ssaoRadius);
					binaryWriter.Write(JsonUtility.ToJson(this.ssaoColor));
					binaryWriter.Write(this.enableBloom);
					binaryWriter.Write(this.bloomIntensity);
					binaryWriter.Write(this.bloomDirt);
					binaryWriter.Write(this.enableDepth);
					binaryWriter.Write(this.depthFocalSize);
					binaryWriter.Write(this.depthAperture);
					binaryWriter.Write(this.enableVignette);
					binaryWriter.Write(this.vignetteVignetting);
					binaryWriter.Write(this.enableEyeAdaptation);
					binaryWriter.Write(this.eyeAdaptationIntensity);
					binaryWriter.Write(this.enableNoise);
					binaryWriter.Write(this.noiseIntensity);
					this.cameraSaveData.Save(binaryWriter);
					for (int i = 0; i < 10; i++)
					{
						this.cameraData[i].Save(binaryWriter);
					}
					binaryWriter.Write(JsonUtility.ToJson(this.cameraLightColor));
					binaryWriter.Write(this.cameraLightIntensity);
					binaryWriter.Write(this.cameraLightRot[0]);
					binaryWriter.Write(this.cameraLightRot[1]);
					binaryWriter.Write(this.cameraLightShadow);
					binaryWriter.Write(this.cameraMethod);
					this.bgmCtrl.Save(binaryWriter, this.m_Version);
					this.envCtrl.Save(binaryWriter, this.m_Version);
					this.outsideSoundCtrl.Save(binaryWriter, this.m_Version);
					binaryWriter.Write(this.background);
					binaryWriter.Write(this.skybox);
					binaryWriter.Write("【PHStudio】");
				}
			}
			return true;
		}

		// Token: 0x06001DDB RID: 7643 RVA: 0x000BD0D8 File Offset: 0x000BB2D8
		public void Save(BinaryWriter _writer, Dictionary<int, ObjectInfo> _dicObject)
		{
			int count = _dicObject.Count;
			_writer.Write(count);
			foreach (KeyValuePair<int, ObjectInfo> keyValuePair in _dicObject)
			{
				_writer.Write(keyValuePair.Key);
				keyValuePair.Value.Save(_writer, this.m_Version);
			}
		}

		// Token: 0x06001DDC RID: 7644 RVA: 0x000BD158 File Offset: 0x000BB358
		public bool Load(string _path)
		{
			Version version;
			return this.Load(_path, out version);
		}

		// Token: 0x06001DDD RID: 7645 RVA: 0x000BD170 File Offset: 0x000BB370
		public bool Load(string _path, out Version _dataVersion)
		{
			using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					PngFile.SkipPng(binaryReader);
					Version version = new Version(binaryReader.ReadString());
					int num = binaryReader.ReadInt32();
					for (int i = 0; i < num; i++)
					{
						int num2 = binaryReader.ReadInt32();
						int num3 = binaryReader.ReadInt32();
						ObjectInfo objectInfo = null;
						switch (num3)
						{
						case 0:
							objectInfo = new OICharInfo(null, -1);
							break;
						case 1:
							objectInfo = new OIItemInfo(-1, -1);
							break;
						case 2:
							objectInfo = new OILightInfo(-1, -1);
							break;
						case 3:
							objectInfo = new OIFolderInfo(-1);
							break;
						default:
							GlobalData.Debug_LogWarning(string.Format("対象外 : {0}", num3));
							break;
						}
						objectInfo.Load(binaryReader, version, false, true);
						this.dicObject.Add(num2, objectInfo);
						this.hashIndex.Add(num2);
					}
					this.map = binaryReader.ReadInt32();
					this.caMap.Load(binaryReader);
					if (version.CompareTo(new Version(0, 1, 3)) >= 0)
					{
						this.atmosphere = binaryReader.ReadInt32();
					}
					this.enableSSAO = binaryReader.ReadBoolean();
					this.ssaoIntensity = binaryReader.ReadSingle();
					this.ssaoRadius = binaryReader.ReadSingle();
					this.ssaoColor = JsonUtility.FromJson<Color>(binaryReader.ReadString());
					this.enableBloom = binaryReader.ReadBoolean();
					this.bloomIntensity = binaryReader.ReadSingle();
					this.bloomDirt = binaryReader.ReadBoolean();
					this.enableDepth = binaryReader.ReadBoolean();
					this.depthFocalSize = binaryReader.ReadSingle();
					this.depthAperture = binaryReader.ReadSingle();
					this.enableVignette = binaryReader.ReadBoolean();
					this.vignetteVignetting = binaryReader.ReadSingle();
					this.enableEyeAdaptation = binaryReader.ReadBoolean();
					this.eyeAdaptationIntensity = binaryReader.ReadSingle();
					this.enableNoise = binaryReader.ReadBoolean();
					this.noiseIntensity = binaryReader.ReadSingle();
					if (this.cameraSaveData == null)
					{
						this.cameraSaveData = new CameraControl.CameraData();
					}
					this.cameraSaveData.Load(binaryReader);
					for (int j = 0; j < 10; j++)
					{
						CameraControl.CameraData cameraData = new CameraControl.CameraData();
						cameraData.Load(binaryReader);
						this.cameraData[j] = cameraData;
					}
					this.cameraLightColor = JsonUtility.FromJson<Color>(binaryReader.ReadString());
					this.cameraLightIntensity = binaryReader.ReadSingle();
					this.cameraLightRot[0] = binaryReader.ReadSingle();
					this.cameraLightRot[1] = binaryReader.ReadSingle();
					this.cameraLightShadow = binaryReader.ReadBoolean();
					if (version.CompareTo(new Version(1, 1, 0)) >= 0)
					{
						this.cameraMethod = binaryReader.ReadInt32();
					}
					this.bgmCtrl.Load(binaryReader, version);
					this.envCtrl.Load(binaryReader, version);
					this.outsideSoundCtrl.Load(binaryReader, version);
					this.background = binaryReader.ReadString();
					_dataVersion = version;
					if (version.CompareTo(new Version(1, 1, 0)) >= 0)
					{
						this.skybox = binaryReader.ReadInt32();
					}
				}
			}
			return true;
		}

		// Token: 0x06001DDE RID: 7646 RVA: 0x000BD4CC File Offset: 0x000BB6CC
		public bool Import(string _path)
		{
			using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					PngFile.SkipPng(binaryReader);
					Version version = new Version(binaryReader.ReadString());
					this.Import(binaryReader, version);
				}
			}
			return true;
		}

		// Token: 0x06001DDF RID: 7647 RVA: 0x000BD548 File Offset: 0x000BB748
		public void Import(BinaryReader _reader, Version _version)
		{
			this.dicImport = new Dictionary<int, ObjectInfo>();
			this.dicChangeKey = new Dictionary<int, int>();
			int num = _reader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				int value = _reader.ReadInt32();
				int num2 = _reader.ReadInt32();
				ObjectInfo objectInfo = null;
				switch (num2)
				{
				case 0:
					objectInfo = new OICharInfo(null, Studio.GetNewIndex());
					break;
				case 1:
					objectInfo = new OIItemInfo(-1, Studio.GetNewIndex());
					break;
				case 2:
					objectInfo = new OILightInfo(-1, Studio.GetNewIndex());
					break;
				case 3:
					objectInfo = new OIFolderInfo(Studio.GetNewIndex());
					break;
				default:
					GlobalData.Debug_LogWarning(string.Format("対象外 : {0}", num2));
					break;
				}
				objectInfo.Load(_reader, _version, true, true);
				this.dicObject.Add(objectInfo.dicKey, objectInfo);
				this.dicImport.Add(objectInfo.dicKey, objectInfo);
				this.dicChangeKey.Add(objectInfo.dicKey, value);
			}
		}

		// Token: 0x06001DE0 RID: 7648 RVA: 0x000BD658 File Offset: 0x000BB858
		private byte[] CreatePngScreen(int _width, int _height)
		{
			Texture2D texture2D = new Texture2D(_width, _height, TextureFormat.RGB24, false);
			int antiAliasing = (QualitySettings.antiAliasing != 0) ? QualitySettings.antiAliasing : 1;
			RenderTexture temporary = RenderTexture.GetTemporary(_width, _height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, antiAliasing);
			Graphics.Blit(this.gameScreenShotAssist.rtCamera, temporary);
			Graphics.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), this.gameScreenShotAssist.rtCamera);
			RenderTexture.active = temporary;
			texture2D.ReadPixels(new Rect(0f, 0f, (float)_width, (float)_height), 0, 0);
			texture2D.Apply();
			RenderTexture.active = null;
			byte[] result = texture2D.EncodeToPNG();
			RenderTexture.ReleaseTemporary(temporary);
			return result;
		}

		// Token: 0x04002049 RID: 8265
		private readonly Version m_Version = new Version(1, 1, 0);

		// Token: 0x0400204A RID: 8266
		public Dictionary<int, ObjectInfo> dicObject;

		// Token: 0x0400204B RID: 8267
		public int map;

		// Token: 0x0400204C RID: 8268
		public ChangeAmount caMap = new ChangeAmount();

		// Token: 0x0400204D RID: 8269
		public int atmosphere;

		// Token: 0x0400204E RID: 8270
		public bool enableSSAO;

		// Token: 0x0400204F RID: 8271
		public float ssaoIntensity;

		// Token: 0x04002050 RID: 8272
		public float ssaoRadius;

		// Token: 0x04002051 RID: 8273
		public Color ssaoColor;

		// Token: 0x04002052 RID: 8274
		public bool enableBloom;

		// Token: 0x04002053 RID: 8275
		public float bloomIntensity;

		// Token: 0x04002054 RID: 8276
		public bool bloomDirt;

		// Token: 0x04002055 RID: 8277
		public bool enableDepth;

		// Token: 0x04002056 RID: 8278
		public float depthFocalSize;

		// Token: 0x04002057 RID: 8279
		public float depthAperture;

		// Token: 0x04002058 RID: 8280
		public bool enableVignette;

		// Token: 0x04002059 RID: 8281
		public float vignetteVignetting;

		// Token: 0x0400205A RID: 8282
		public bool enableEyeAdaptation;

		// Token: 0x0400205B RID: 8283
		public float eyeAdaptationIntensity;

		// Token: 0x0400205C RID: 8284
		public bool enableNoise;

		// Token: 0x0400205D RID: 8285
		public float noiseIntensity;

		// Token: 0x0400205E RID: 8286
		public CameraControl.CameraData cameraSaveData;

		// Token: 0x0400205F RID: 8287
		public CameraControl.CameraData[] cameraData;

		// Token: 0x04002060 RID: 8288
		public Color cameraLightColor;

		// Token: 0x04002061 RID: 8289
		public float cameraLightIntensity;

		// Token: 0x04002062 RID: 8290
		public float[] cameraLightRot = new float[2];

		// Token: 0x04002063 RID: 8291
		public bool cameraLightShadow = true;

		// Token: 0x04002064 RID: 8292
		public int cameraMethod;

		// Token: 0x04002065 RID: 8293
		public BGMCtrl bgmCtrl = new BGMCtrl();

		// Token: 0x04002066 RID: 8294
		public ENVCtrl envCtrl = new ENVCtrl();

		// Token: 0x04002067 RID: 8295
		public OutsideSoundCtrl outsideSoundCtrl = new OutsideSoundCtrl();

		// Token: 0x04002068 RID: 8296
		public string background = string.Empty;

		// Token: 0x04002069 RID: 8297
		public int skybox;

		// Token: 0x0400206A RID: 8298
		private HashSet<int> hashIndex;

		// Token: 0x0400206B RID: 8299
		private GameScreenShotAssist gameScreenShotAssist;
	}
}
